<?php

/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */


/**
 * WBFrame
 *
 * @package php.ui.winbinder
 */
class WBFrame extends WBControl { 

	private $_rootPanel = null;

	public function __construct($options = array()) { 
		$options['class'] = Frame;

		parent::__construct($options);
	}

	protected function initCreate() {
		$style = $this->getOption('style'); 
		if (isset($this->image)) { 
			$style |= WBC_IMAGE;
		}
		
		$this->setOption('style', $style);
	}

	// 객체 초기화 
	protected function initComponent() { 

		parent::initComponent();	

		// RootPanel 설정 
		$this->setRootPanel(new WBPanel(array(
			'parent' => $this,
			'layout' => 'full'
		)));

		if (isset($this->image))	{ 
			if(is_string($this->getOption('image'))) { 
				$this->setOption('image', realpath($this->getOption('image')));
			} 
			
			$this->setImage($this->getOption('image'));
			
		}

		// 텍스트 설정 
		if (isset($this->text))		$this->setText($this->getOption('text'));

		// 레이아웃 설정 
		if (isset($this->layout))	$this->setLayout($this->getOption('layout'));
		
		if (isset($this->controls)) { 
			foreach ($this->getOption('controls') as $control) { 
				$this->add($control);
			}
		}		
	}

	/** 
	 * 레이아웃 실행 
	 *
	 */
	public function doLayout() { 
		if ($this->_rootPanel instanceof WBPanel) { 

			$arr = wb_get_size($this->getText());
			
			// 최초 크기 설정 
			$bounds	= $this->getSize(true);
			
			$this->_rootPanel->setBounds(
				4 ,
				$arr[1],
				$bounds['width'] - 9 , 
				$bounds['height'] - ($arr[1]+4)
			);
		}
	}

	/** 
	 * root panel 설정 
	 *
	 */
	public function setRootPanel($panel) { 
		$this->_rootPanel = $panel; 
	}

	/** 
	 * root panel 얻어오기 
	 *
	 * @return WBPanel 
	 */
	public function getRootPanel() { 
		return $this->_rootPanel;
	}

	/** 
	 * component 추가 
	 *
	 * @return WBComponent 
	 */
	public function add($component) { 
		if ($this->_rootPanel instanceof WBPanel) { 
			$component = $this->_rootPanel->add($component);
			
		}
		  
		$component->extern('SetParent', $this);

		return $component;
	}

	/** 
	 * root panel 에 레이아웃 설정 
	 *
	 *
	 */
	public function setLayout($layout) { 
		if ($this->_rootPanel instanceof WBPanel) { 
			$this->_rootPanel->setLayout($layout);
		}
	}
	
	public function setVisible($isVisible = true) { 
		parent::setVisible($isVisible);
		
		if ($this->_rootPanel instanceof WBPanel) { 
			$this->_rootPanel->setVisible($isVisible);
		}
	}
}

?>